package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	[SWF(width = 1024, height = 576, frameRate = 30)]
	public class FireJump extends Sprite
	{
		public function FireJump()
		{
			Init();
			stage.addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		private function handleClick(event:MouseEvent):void
		{
			goFullScreen();
		}
		
		private function goFullScreen():void
		{
			if (stage.displayState == StageDisplayState.NORMAL)
				stage.displayState = StageDisplayState.FULL_SCREEN;
			else
				stage.displayState = StageDisplayState.NORMAL;
		}
		
		private function Init():void
		{
			stage.frameRate = 30;
			var px:Number;
			var py:Number;
			var angle:Number;
			var R:Number=130;// 外圆半径
			var r:Number=50;// 内圆半径
			var i:int=0;
			var col:uint;
			var m:int=0;
			var c:Object={r:-5,g:-5,b:-20};
			var sp:Sprite=new Sprite();
			sp.x=stage.stageWidth/2;
			sp.y=stage.stageHeight/2;
			sp.graphics.lineStyle(1,0xffffff);
			addChild(sp);
			
			for (i=0; i < 360 * 8; i++)
			{
				angle = i * Math.PI / 180;
				myrot();
				if(i ==0)
				{
					sp.graphics.moveTo(px, py);
				}
				else
				{
					sp.graphics.lineTo(px, py);
				}
			}
			
			var ball:Sprite = new Sprite();
			sp.addChild(ball);
			ball.cacheAsBitmap=true;
			
			function myrot():void
			{
				px=(R+r)*Math.cos(angle)+r*Math.cos((R-r)/r*angle);
				py=(R+r)*Math.sin(angle)-r*Math.sin((R-r)/r*angle);
			}
			
			var map1:BitmapData=new BitmapData(1024,576,false,0);
			var map2:BitmapData=new BitmapData(1024,576,false,0);
			map2.perlinNoise(10,160,2,10,true,true,1,true);
			var perMc:Sprite=new Sprite();// 装有杂点容器
			var con1:Sprite=new Sprite();// 父容器
			var con:Sprite=new Sprite();// 小容器
			addChild(con);
			con.addChild(sp);// 装画的圆
			con1.addChild(perMc);
			var perBit:Bitmap=new Bitmap(map2);
			perMc.addChild(perBit);
			addChild(new Bitmap(map1));// 场景上的底图
			var bit:Bitmap=new Bitmap(map2);
			bit.blendMode=BlendMode.OVERLAY;// 与底色 <50%变暗
			
			addEventListener(Event.ENTER_FRAME,frame);
			function frame(e):void 
			{
				angle=i%720*Math.PI/180;
				myrot();
				ball.x=px;
				ball.y=py;
				i+=2;
				sp.rotation++;
				map1.draw(con);//小圆环
				map2.draw(con1);//有布林杂点的图
				map1.applyFilter(map1,map1.rect,new Point(),new BlurFilter(2,2,1));
				map1.colorTransform(map1.rect,new ColorTransform(1,1,1,1,c.r,c.g,c.b));
				map1.draw(map1.clone(),new Matrix(1,0,0,1,0,-2));
				m++;
				switch (m%300) 
				{
					case 50 :
						c.g=c.b;
						break;
					case 100 :
						c.r=c.b,c.g=c.b=-5;
						break;
					case 150 :
						c.b=-20;
						break;
					case 200 :
						c.g=-20,c.r=c.b=-5;
						break;
					case 250 :
						c.r=c.g;
						break;
					case 0 :
						c.r=c.g=-5,c.b=-20;
						break;
				}
			}
		}
	}
}